<?php
session_start ();
// 判断用户是否已经登录
if (! isset ( $_SESSION ["userinfo"] ) and empty ( $_SESSION ["userinfo"] ["userid"] )) {
	session_unset ();
	session_destroy ();
	header ( "location:../index.php" );
	exit ();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="./style/booksList.css" />
</head>
<body>
<?php
include_once '../tools/SqlHelper.class.php';
$sqlHelper = new SqlHelper ();
if (isset ( $_GET ['userid'] )) {
	$userid = $_GET ['userid'];
	$sql = "DELETE FROM `admin_tb` WHERE `ad_id`='$userid'";
	$resultA = $sqlHelper->execute_dql ( $sql );
	if (! ! $resultA) {
		echo "<script>alert('删除成功')</script>";
	} else {
		echo "<script>alert('删除失败')</script>";
	}
}
// 每页的显示条数
$page_size = 9;
// 当前页码
$page_num = 1;
if (is_numeric ( $_GET ['page'] )) {
	$page_num = ( int ) $_GET ['page'];
}
// 总条数
// $resultA = mysql_query ( "select count(bookid) as total from book_info" );
$sql = "select count(idadmin_tb) from `admin_tb`";
// 创建一个SqlHelper对象
$resultA = $sqlHelper->execute_dql ( $sql );
$row = mysql_fetch_array ( $resultA );
$data_count = $row ['0'];
// 总页数
$page_count = ceil ( $data_count / $page_size );

// 当前页码中的数据
$offset = ($page_num - 1) * $page_size;
$sql = "select * from admin_tb where 1=1 order by idadmin_tb asc limit $offset , $page_size";
$resultB = $sqlHelper->execute_dql ( $sql );
// $resultB = mysql_query ( "select * from book_info where 1=1 order by _id asc limit $offset , $page_size" );
$row = mysql_fetch_array ( $resultB );
?>
	<form action="./adminList.php" target="frm" method="get">
		<div>
			<h1>会员列表</h1>
			<table class="tb_list">
				<tr>
					<th>管理员账户名</th>
					<th>删除</th>
				</tr>
				<?php
				// 创建页面元素数据
				if (! $row) {
					echo "<tr><td colspan='3'>暂无数据</td></tr>";
				} else {
					do {
						echo "<tr>";
						echo "<td><a href='afterAdmin.php?_id=" . $row ['idadmin_tb'] . "'>" . $row ['ad_id'] . "</a></td>";
						echo "<td><a href='adminList.php?userid=" . $row ['ad_id'] . "'>删除</a></td>";
						echo "</tr>";
					} while ( ! ! ($row = mysql_fetch_array ( $resultB )) );
				}
				?>
			</table>
		</div>
		<div class="table_style_pager">
			<table class="tb_pager">
				<tr>
					<td class="td1"><?php
					if ($page_num > 1) {
						echo "<a href='adminList.php?page=1' target='_self'>首页</a>&nbsp;";
						echo "<a href='adminList.php?page=" . ($page_num - 1) . "' target='_self'>上一页</a>&nbsp;";
					}
					if ($page_num < $page_count) {
						echo "<a href='adminList.php?page=" . ($page_num + 1) . "' target='_self'>下一页</a>&nbsp;";
						echo "<a href='adminList.php?page=" . $page_count . "' target='_self'>尾页</a>&nbsp;";
					}
					?></td>
					<td class="td2">当前页<?php echo $page_num."/".$page_count; ?></td>
					<td class="td2">共<?php echo $data_count; ?>条记录</td>
				</tr>
			</table>
			<h2></h2>
			<div class="table_style_page">
				<label> 跳转到： </label> <input type="text" name="page">页</input> <input
					class="button" name="user_submit" type="submit" value="跳转" />
			</div>
		</div>
	</form>
</body>
</html>
